Skip to content

Some improvements to util.HashSet and HashMap #9865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 29, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 24, 2020

No description provided.

Allow to record total sizes of collections on which
some selected operation is performed.

# Conflicts:
#	compiler/src/dotty/tools/dotc/transform/Instrumentation.scala
When tranisitioning from dense to hashing, we grow the table more than usual
since otherwise we'd have to grow it again at the very next addEntry. The
condition for this was wrong for HashMaps.
Make criterion when to fill a hole in a HashMap or HashSet remove more robust.
The old criterion relied on fill factor always being less than 0.5.
The new criterion works for arbitrary fill factors.
The code was taken from scala.collection.mutable.AnyRefMap
@odersky
Copy link
Contributor Author

odersky commented Sep 24, 2020

test performance please

@dottybot
Copy link
Member

performance test scheduled: 2 job(s) in queue, 1 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/9865/ to see the changes.

Benchmarks is based on merging with master (85d1322)

@odersky odersky requested a review from liufengyun September 25, 2020 07:39
@odersky odersky assigned odersky and liufengyun and unassigned odersky Sep 25, 2020
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -156,7 +158,7 @@ abstract class GenericHashMap[Key, Value]
protected def growTable(): Unit =
val oldTable = table
val newLength =
if oldTable.length == DenseLimit then DenseLimit * 2 * roundToPower(capacityMultiple)
if table.length == DenseLimit * 2 then table.length * roundToPower(capacityMultiple)
Copy link
Contributor

@liufengyun liufengyun Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why we need the if here, instead of simply growing the table, since all calls to growTable is guarded by if used > limit. Is it to just create a larger array at the size DenseLimit * 2 (instead of simply doubling the size)?

Meanwhile, if we change the code here, do we need similar changes in HashSet.growTable?

@liufengyun liufengyun merged commit 6f632b4 into scala:master Sep 29, 2020
@liufengyun liufengyun deleted the fix-sets-maps branch September 29, 2020 12:26
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants